home *** CD-ROM | disk | FTP | other *** search
Text File | 1994-11-21 | 23.5 KB | 910 lines | [TEXT/MPCC] |
- /*
- ** CTCPResolverCall.cp
- **
- ** TurboTCP support library
- ** TCP resolver call class
- **
- ** Copyright © 1993-94, FrostByte Design / Eric Scouten
- ** Some portions adapted from file “dnr.c” Copyright © 1988 by Apple Computer. All rights reserved.
- **
- */
-
-
- #include "CTCPResolverCall.h"
-
- #include <Folders.h>
- #include <GestaltEqu.h>
- #include <Traps.h>
- #include "OSChecks.h"
- #include "TCLUtilities.h"
- #include "CPtrArray.h"
-
-
- #ifndef TCL_NO_TEMPLATES
- class CTCPResolverCallList : public CPtrArray<CTCPResolverCall> {};
- #else
- TM_DECLARE_CPtrArray(CTCPResolverCall);
- #endif
-
-
- // procedure code numbers for DNR code segment
-
- #define OPENRESOLVER 1L
- #define CLOSERESOLVER 2L
- #define STRTOADDR 3L
- #define ADDRTOSTR 4L
- #define ENUMCACHE 5L
- #define ADDRTONAME 6L
- #define HINFO 7L
- #define MXINFO 8L
-
-
- // —— class variables ——
-
- Handle CTCPResolverCall::macDNRcode = NULL;
- UniversalProcPtr CTCPResolverCall::macDNRentry = NULL;
- #if GENERATINGCFM
- ResultUPP CTCPResolverCall::StrToAddrUPP = NewResultProc(CTCPResolverCall::PostponeStrToAddr);
- ResultUPP CTCPResolverCall::AddrToNameUPP = NewResultProc(CTCPResolverCall::PostponeAddrToName);
- Result2UPP CTCPResolverCall::HInfoUPP = NewResult2Proc(CTCPResolverCall::PostponeHInfo);
- Result2UPP CTCPResolverCall::MXInfoUPP = NewResult2Proc(CTCPResolverCall::PostponeMXInfo);
- #endif
-
-
- TCL_DEFINE_CLASS_M0(CTCPResolverCall);
-
-
- /*______________________________________________________________________
- **
- ** interfaces to TCP DNR (adapted from latest <dnr.c>
- **
- */
-
- // NOTE: The dnr.c file created for universal headers contained an error. All of the selectors
- // are treated by the DNR as long values, not short. This has been corrected in TurboTCP.
-
- extern "C" {
-
- typedef OSErr (*OpenResolverProcPtr)(long selector, char* fileName);
- typedef OSErr (*CloseResolverProcPtr)(long selector);
- typedef OSErr (*StrToAddrProcPtr)(long selector, char* hostName, struct hostInfo* rtnStruct,
- long resultProc, char* userData);
- typedef OSErr (*AddrToStrProcPtr)(long selector, long address, char* hostName);
- typedef OSErr (*AddrToNameProcPtr)(long selector, unsigned long addr, struct hostInfo* rtnStruct,
- long resultProc, char* userData);
- typedef OSErr (*HInfoProcPtr)(long selector, char* hostName, struct returnRec* returnRecPtr,
- long resultProc, char* userData);
- typedef OSErr (*MXInfoProcPtr)(long selector, char* hostName, struct returnRec* returnRecPtr,
- long resultProc, char* userData);
-
- };
-
- #if GENERATINGCFM
-
- enum {
- uppOpenResolverProcInfo = kCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(short)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char*)))
- };
-
- enum {
- uppCloseResolverProcInfo = kCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(short)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))
- };
- enum {
- uppStrToAddrProcInfo = kCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(short)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char*)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct hostInfo*)))
- | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
- | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(char*)))
- };
- enum {
- uppAddrToStrProcInfo = kCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(short)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(unsigned long)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(char*)))
- };
- enum {
- uppAddrToNameProcInfo = kCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(short)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(unsigned long)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct hostInfo*)))
- | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
- | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(char*)))
-
- };
- enum {
- uppHInfoProcInfo = kCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(short)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char*)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct returnRec*)))
- | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
- | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(char*)))
-
- };
- enum {
- uppMXInfoProcInfo = kCStackBased
- | RESULT_SIZE(SIZE_CODE(sizeof(short)))
- | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))
- | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(char*)))
- | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(struct returnRec*)))
- | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))
- | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(char*)))
-
- };
-
- typedef UniversalProcPtr OpenResolverUPP;
- typedef UniversalProcPtr CloseResolverUPP;
- typedef UniversalProcPtr StrToAddrUPP;
- typedef UniversalProcPtr AddrToStrUPP;
- typedef UniversalProcPtr AddrToNameUPP;
- typedef UniversalProcPtr HInfoUPP;
- typedef UniversalProcPtr MXInfoUPP;
-
- #define CallOpenResolverProc(userRoutine, selector, filename) \
- CallUniversalProc(userRoutine, uppOpenResolverProcInfo, selector, filename)
- #define CallCloseResolverProc(userRoutine, selector) \
- CallUniversalProc(userRoutine, uppCloseResolverProcInfo, selector)
- #define CallStrToAddrProc(userRoutine, selector, hostName, rtnStruct, resultProc, userData) \
- CallUniversalProc(userRoutine, uppStrToAddrProcInfo, selector, hostName, rtnStruct, resultProc, userData)
- #define CallAddrToStrProc(userRoutine, selector, address, hostName) \
- CallUniversalProc(userRoutine, uppAddrToStrProcInfo, selector, address, hostName)
- #define CallAddrToNameProc(userRoutine, selector, addr, rtnStruct, resultProc, userData) \
- CallUniversalProc(userRoutine, uppAddrToNameProcInfo, selector, addr, rtnStruct, resultProc, userData)
- #define CallHInfoProc(userRoutine, selector, hostName, returnRecPtr, resultProc, userData) \
- CallUniversalProc(userRoutine, uppHInfoProcInfo, selector, hostName, returnRecPtr, resultProc, userData)
- #define CallMXInfoProc(userRoutine, selector, hostName, returnRecPtr, resultProc, userData) \
- CallUniversalProc(userRoutine, selector, hostName, returnRecPtr, resultProc, userData)
-
- #else // #if GENERATINGCFM
-
- typedef OpenResolverProcPtr OpenResolverUPP;
- typedef CloseResolverProcPtr CloseResolverUPP;
- typedef StrToAddrProcPtr StrToAddrUPP;
- typedef AddrToStrProcPtr AddrToStrUPP;
- typedef AddrToNameProcPtr AddrToNameUPP;
- typedef HInfoProcPtr HInfoUPP;
- typedef MXInfoProcPtr MXInfoUPP;
-
- #define CallOpenResolverProc(userRoutine, selector, filename) \
- (*((OpenResolverProcPtr) userRoutine))(selector, filename)
- #define CallCloseResolverProc(userRoutine, selector) \
- (*((CloseResolverProcPtr) userRoutine))(selector)
- #define CallStrToAddrProc(userRoutine, selector, hostName, rtnStruct, resultProc, userData) \
- (*((StrToAddrProcPtr) userRoutine))(selector, hostName, rtnStruct, resultProc, userData)
- #define CallAddrToStrProc(userRoutine, selector, address, hostName) \
- (*((AddrToStrProcPtr) userRoutine))(selector, address, hostName)
- #define CallAddrToNameProc(userRoutine, selector, addr, rtnStruct, resultProc, userData) \
- (*((AddrToNameProcPtr) userRoutine))(selector, addr, rtnStruct, resultProc, userData)
- #define CallHInfoProc(userRoutine, selector, hostName, returnRecPtr, resultProc, userData) \
- (*((HInfoProcPtr) userRoutine))(selector, hostName, returnRecPtr, resultProc, userData)
- #define CallMXInfoProc(userRoutine, selector, hostName, returnRecPtr, resultProc, userData) \
- (*((MXInfoProcPtr) userRoutine))(selector, hostName, returnRecPtr, resultProc, userData)
-
- #endif // #ifdef GENERATINGCFM
-
-
- // —— constructor/destructor ——
-
- /*______________________________________________________________________
- **
- ** constructor
- **
- ** Initialize the resolver object.
- **
- */
-
- CTCPResolverCall::CTCPResolverCall(CTCPEndpoint& theEndpoint)
- : itsEndpoint(&theEndpoint), qEntry(this)
-
- {
- // clear variables
-
- inUse = FALSE;
- disposeOnCompletion = FALSE;
- pendingNotify = notifNone;
- qEntry.qType = resolverCall;
- TCL_END_CONSTRUCTOR;
- }
-
-
- /*______________________________________________________________________
- **
- ** destructor
- **
- ** DO NOT CALL THIS METHOD! Use Dispose() instead.
- **
- */
-
- CTCPResolverCall::~CTCPResolverCall()
- {
- TCL_START_DESTRUCTOR;
- }
-
-
- /*______________________________________________________________________
- **
- ** Dispose
- **
- ** Get rid of the resolver object. If a resolver operation is in progress, will dispose of
- ** itself when the current resolver operation is completed.
- **
- ** Use Dispose() instead of destructor since the object may need to remain around for a
- ** while.
- **
- */
-
- void CTCPResolverCall::Dispose()
-
- {
- if (inUse)
- disposeOnCompletion = TRUE;
- else
- delete this;
- }
-
-
- // —— initiate resolver calls ——
-
- /*______________________________________________________________________
- **
- ** DoStrToAddr
- **
- ** Get the IP address of a host named by a DNS or dotted decimal string. Completion is
- ** handled by HandleStrToAddr.
- **
- ** theHostName (char*): whose IP address do we need?
- **
- */
-
- void CTCPResolverCall::DoStrToAddr(char* theHostName)
-
- {
- OSErr theResult;
-
- if (inUse)
- FailOSErr(resolverInUse);
- if (!(CTCPDriver::gTCPDriver)->CheckResolver())
- FailOSErr(noResolverErr);
-
- inUse = TRUE;
- (CTCPDriver::gTCPDriver)->RegisterActiveResolver(this);
- BlockMove(theHostName, &hostName, 255);
-
- #if GENERATINGCFM // seems to be buggy here…
- theResult = CallStrToAddrProc(macDNRentry, STRTOADDR, (char*) &hostName, &theHostInfo,
- (long) StrToAddrUPP, (char*) this);
- #else
- theResult = CallStrToAddrProc(macDNRentry, STRTOADDR, (char*) &hostName, &theHostInfo,
- (long) &PostponeStrToAddr, (char*) this);
- #endif
-
-
- // if call was completed immediately (with error or not), process it immediately
-
- if (theResult != cacheFault) {
- inUse = FALSE;
- (CTCPDriver::gTCPDriver)->RemoveActiveResolver(this);
- HandleStrToAddr();
- }
- }
-
-
- /*______________________________________________________________________
- **
- ** DoAddrToStr (static method)
- **
- ** Convert an IP address to dotted decimal notation. This call can be used while the resolver
- ** object is otherwise in use, and is completed immediately.
- **
- ** theIPaddr (ip_addr): the address to convert
- ** theString (char*): where to send the completed string (min. 16 chars)
- **
- */
-
- void CTCPResolverCall::DoAddrToStr(ip_addr theIPaddr, char* theString)
-
- {
- if (!(CTCPDriver::gTCPDriver)->CheckResolver())
- FailOSErr(noResolverErr);
- CallAddrToStrProc(macDNRentry, ADDRTOSTR, theIPaddr, theString);
- }
-
-
- /*______________________________________________________________________
- **
- ** DoAddrToName
- **
- ** Get the canonical name of a host as specified by IP address. Completion is handled by
- ** HandleAddrToName method.
- **
- ** theIPaddr (ip_addr): the IP address to query
- **
- */
-
- void CTCPResolverCall::DoAddrToName(ip_addr theIPaddr)
-
- {
- OSErr theResult;
-
- if (inUse)
- FailOSErr(resolverInUse);
- if (!(CTCPDriver::gTCPDriver)->CheckResolver())
- FailOSErr(noResolverErr);
-
- inUse = TRUE;
- (CTCPDriver::gTCPDriver)->RegisterActiveResolver(this);
-
- #if GENERATINGCFM // seems to be buggy here…
- theResult = CallAddrToNameProc(macDNRentry, ADDRTONAME, theIPaddr, &theHostInfo,
- (long) AddrToNameUPP, (char*) this);
- #else
- theResult = CallAddrToNameProc(macDNRentry, ADDRTONAME, theIPaddr, &theHostInfo,
- (long) &PostponeAddrToName, (char*) this);
- #endif
-
-
- // if call was completed immediately (with error or not), process it immediately
-
- if (theResult != cacheFault) {
- inUse = FALSE;
- (CTCPDriver::gTCPDriver)->RemoveActiveResolver(this);
- HandleAddrToName();
- }
- }
-
-
- /*______________________________________________________________________
- **
- ** DoHInfo
- **
- ** Get the CPU type and operating system type of a remote host. Completion is handled by
- ** HandleHInfo.
- **
- ** theHostName (char*): who we askin’ ‘bout anyway?
- **
- */
-
- void CTCPResolverCall::DoHInfo(char* theHostName)
-
- {
- OSErr theResult;
-
- if (inUse)
- FailOSErr(resolverInUse);
- if (!(CTCPDriver::gTCPDriver)->CheckResolver())
- FailOSErr(noResolverErr);
-
- inUse = TRUE;
- (CTCPDriver::gTCPDriver)->RegisterActiveResolver(this);
- BlockMove(theHostName, &hostName, 255);
-
- #if GENERATINGCFM // seems to be buggy here…
- theResult = CallHInfoProc(macDNRentry, HINFO, (char*) &hostName, &theHMXInfo,
- (long) HInfoUPP, (char*) this);
- #else
- theResult = CallHInfoProc(macDNRentry, HINFO, (char*) &hostName, &theHMXInfo,
- (long) &PostponeHInfo, (char*) this);
- #endif
-
-
- // if call was completed immediately (with error or not), process it immediately
-
- if (theResult != cacheFault) {
- inUse = FALSE;
- (CTCPDriver::gTCPDriver)->RemoveActiveResolver(this);
- HandleHInfo();
- }
- }
-
-
- /*______________________________________________________________________
- **
- ** DoMXInfo
- **
- ** Get the mailbox exchange (MX) info of a remote host. Completion is handled by
- ** HandleMXInfo.
- **
- ** theHostName (char*): who we askin’ ‘bout anyway?
- **
- */
-
- void CTCPResolverCall::DoMXInfo(char* theHostName)
-
- {
- OSErr theResult;
-
- if (inUse)
- FailOSErr(resolverInUse);
- if (!(CTCPDriver::gTCPDriver)->CheckResolver())
- FailOSErr(noResolverErr);
-
- inUse = TRUE;
- (CTCPDriver::gTCPDriver)->RegisterActiveResolver(this);
- BlockMove(theHostName, &hostName, 255);
- #if GENERATINGCFM // seems to be buggy here…
- theResult = CallMXInfoProc(macDNRentry, MXINFO, (char*) &hostName, &theHMXInfo,
- (long) MXInfoUPP, (char*) this);
- #else
- theResult = CallMXInfoProc(macDNRentry, MXINFO, (char*) &hostName, &theHMXInfo,
- (long) &PostponeMXInfo, (char*) this);
- #endif
-
-
- // if call was completed immediately (with error or not), process it immediately
-
- if (theResult != cacheFault) {
- inUse = FALSE;
- (CTCPDriver::gTCPDriver)->RemoveActiveResolver(this);
- HandleMXInfo();
- }
- }
-
-
- // —— respond to completion of resolver calls ——
-
- /*______________________________________________________________________
- **
- ** ProcessNotify (private method)
- **
- ** Handles any notifications passed to the resolver. This routine is free of interrupt-level
- ** constraints.
- **
- */
-
- void CTCPResolverCall::ProcessNotify(void)
-
- {
- // free this resolver object for future use
-
- (CTCPDriver::gTCPDriver)->RemoveActiveResolver(this);
- inUse = FALSE;
-
-
- // dispatch notification to appropriate routine
-
- switch (pendingNotify) {
- case notifStrToAddr:
- HandleStrToAddr();
- break;
-
- case notifAddrToName:
- HandleAddrToName();
- break;
-
- case notifHInfo:
- HandleHInfo();
- break;
-
- case notifMXInfo:
- HandleMXInfo();
- }
-
-
- // if someone attempted to dispose this earlier, do it now
-
- if (disposeOnCompletion)
- delete this;
-
- }
-
-
- // —— open/close TCP resolver ——
-
- /*______________________________________________________________________
- **
- ** OpenResolver (private static method)
- **
- ** Find the MacTCP DNR code resource and read it. Save the location of the resolver resource
- ** for later use.
- **
- */
-
- void CTCPResolverCall::OpenResolver()
-
- {
- short vRefNum;
- short refnum;
- long dirID;
- short fRef;
- OSErr rc;
-
-
- // is the resolver already there?
-
- if (macDNRentry)
- return;
-
-
- // open the MacTCP driver to get DNR resources
-
- TRY {
- refnum = OpenTheDNR();
- }
- CATCH {
- NO_PROPAGATE; // ignore failures since the resource may
- // have been installed in the System file
- // (if running on a Mac 512Ke)
- }
- ENDTRY;
-
-
- // load the DNR resource package
-
- macDNRcode = GetIndResource('dnrp', 1);
- FailNIL(macDNRcode);
- DetachResource(macDNRcode);
-
- if (refnum != -1)
- CloseResFile(refnum);
-
-
- // lock the DNR resource since it cannot be relocated while opened
-
- MoveHHi(macDNRcode);
- HLock(macDNRcode);
- macDNRentry = (UniversalProcPtr) *macDNRcode;
-
-
- // check for “hosts” file in System Folder (BRB)
-
- GetSystemFolder(&vRefNum, &dirID);
- rc = HOpen(vRefNum, dirID, "\pHosts", fsRdPerm, &fRef);
- switch (rc) {
- case noErr:
- FSClose(fRef);
- break;
-
- case fnfErr:
- if ((rc = HCreate(vRefNum, dirID, "\pHosts", 'ttxt', 'TEXT')) != noErr)
- ErrorAlert(rc, SpecifyMsg(1001, 1));
- break;
-
- default:
- break;
- }
-
-
- // ask the DNR resource to open the resolver
-
- rc = CallOpenResolverProc(macDNRentry, OPENRESOLVER, NULL);
- // send it a null hosts file name
- if (rc != noErr) {
- HUnlock(macDNRcode); // problem with open resolver, flush DNR resource
- DisposHandle(macDNRcode);
- macDNRcode = NULL;
- macDNRentry = NULL;
- FailOSErr(rc); // signal failure of DNR
- }
-
- }
-
-
- /*______________________________________________________________________
- **
- ** CloseResolver (private static method)
- **
- ** Shut down the DNR code resource. Does nothing if the resolver was never loaded.
- **
- */
-
- void CTCPResolverCall::CloseResolver()
-
- {
-
- // ensure that we had a resolver to begin with
-
- if (macDNRentry == NULL)
- return;
-
-
- // call CloseResolver function in DNR
-
- CallCloseResolverProc(macDNRentry, CLOSERESOLVER);
-
-
- // release the DNR code resource
-
- HUnlock(macDNRcode);
- DisposHandle(macDNRcode);
- macDNRcode = NULL;
- macDNRentry = NULL;
-
- }
-
-
- /*______________________________________________________________________
- **
- ** OpenTheDNR (private static method)
- **
- ** Search in several places for the MacTCP DNR code resource. Tries the Control Panels
- ** folder and the System folder.
- **
- ** return (short): reference number to resource file
- **
- */
-
- short CTCPResolverCall::OpenTheDNR()
-
- {
- short refnum;
- short vRefNum;
- long dirID;
-
-
- // first search Control Panels for MacTCP 1.1.x
-
- GetCPanelFolder(&vRefNum, &dirID);
- refnum = SearchFolderForDNRP('cdev', 'ztcp', vRefNum, dirID);
- if (refnum != -1)
- return refnum;
-
-
- // next search System Folder for MacTCP 1.0.x
-
- GetSystemFolder(&vRefNum, &dirID);
- refnum = SearchFolderForDNRP('cdev', 'mtcp', vRefNum, dirID);
- if (refnum != -1)
- return refnum;
-
-
- // finally, search Control Panels for MacTCP 1.0.x
-
- GetCPanelFolder(&vRefNum, &dirID);
- refnum = SearchFolderForDNRP('cdev', 'mtcp', vRefNum, dirID);
- if (refnum != -1)
- return refnum;
-
- return -1;
-
- }
-
-
- /*______________________________________________________________________
- **
- ** SearchFolderForDNRP (private static method)
- **
- ** Search a folder for files that might contain the 'dnrp' resource.
- **
- ** targetType (OSType): file type that we are looking for
- ** targetCreator (OSType): file creator "" ""
- ** vRefNum (short): volume ref num
- ** dirID (long): directory number on the volume
- **
- ** return (short): the refnum of the file if found, -1 if not found
- **
- */
-
- short CTCPResolverCall::SearchFolderForDNRP(long targetType, long targetCreator,
- short vRefNum, long dirID)
-
- {
- HParamBlockRec fi;
- Str255 filename;
- short refnum;
-
-
- // initialize our search mechanism
-
- fi.fileParam.ioCompletion = nil;
- fi.fileParam.ioNamePtr = filename;
- fi.fileParam.ioVRefNum = vRefNum;
- fi.fileParam.ioDirID = dirID;
- fi.fileParam.ioFDirIndex = 1;
-
-
- // keep looking till we run out of files
-
- while (PBHGetFInfo(&fi, false) == noErr) {
-
- // scan the folder for files that match our type & creator
-
- if (fi.fileParam.ioFlFndrInfo.fdType == targetType &&
- fi.fileParam.ioFlFndrInfo.fdCreator == targetCreator) {
-
- // type/creator match, look for the resource
-
- refnum = HOpenResFile(vRefNum, dirID, filename, fsRdPerm);
- if (GetIndResource('dnrp', 1) == NULL)
- CloseResFile(refnum);
- else
- return refnum;
- }
-
- // no match or no resource, try next file in folder
-
- fi.fileParam.ioFDirIndex++;
- fi.fileParam.ioDirID = dirID; // PBHGetFInfo() clobbers ioDirID
- }
-
- return -1; // nothing found
-
- }
-
-
- /*______________________________________________________________________
- **
- ** GetSystemFolder (private static method)
- **
- ** Return the ID of the current system folder.
- **
- ** vRefNumP (short *): returns volume ref number
- ** dirIDP (long *): returns directory ID
- **
- */
-
- void CTCPResolverCall::GetSystemFolder(short* vRefNumP, long* dirIDP)
-
- {
- SysEnvRec info;
- long wdProcID;
-
- SysEnvirons(1, &info);
- if (GetWDInfo(info.sysVRefNum, vRefNumP, dirIDP, &wdProcID) != noErr) {
- *vRefNumP = 0;
- *dirIDP = 0;
- }
- }
-
-
- /*______________________________________________________________________
- **
- ** GetCPanelFolder (private static method)
- **
- ** Return the ID of the current “Control Panels” folder.
- **
- ** vRefNumP (short*): returns volume ref number
- ** dirIDP (long*): returns directory ID
- **
- */
-
- void CTCPResolverCall::GetCPanelFolder(short* vRefNumP, long* dirIDP)
-
- {
- Boolean hasFolderMgr = false;
- long feature;
-
-
- // see if we have the Folder Manager available
-
- if (TrapAvailable((short) _Gestalt))
- if (Gestalt(gestaltFindFolderAttr, &feature) == noErr)
- hasFolderMgr = TRUE;
-
-
- // if folder manager, use it; else return system folder
-
- if (!hasFolderMgr) {
- GetSystemFolder(vRefNumP, dirIDP);
- return;
- }
- else {
- if (FindFolder(kOnSystemDisk, kControlPanelFolderType,
- kDontCreateFolder, vRefNumP, dirIDP) != noErr) {
- *vRefNumP = 0;
- *dirIDP = 0;
- }
- }
-
- }
-
-
- /***********************************************************************
- ************************************************************************
- **
- ** INTERRUPT-LEVEL routines follow. These routines cannot make memory allocations, cannot make
- ** synchronous TCP calls, and cannot use the Think C profiler.
- **
- */
-
- #ifndef __MWERKS__
- //#pragma options(!profile)
- #else
- #pragma profile off
- #endif
-
-
- // —— interrupt-level methods: delay processing for non-interrupt status ——
-
- /*______________________________________________________________________
- **
- ** PostponeNotify (private static method)
- **
- ** Respond to notification that a DNR call was completed. Delays processing of notification
- ** until the next net-event call. This method merely logs the kind of notification and adds this
- ** resolver to the list of resolvers to be processed next time through the event loop.
- **
- ** theNotifType (NotifType): which resolver call was completed
- **
- */
-
- void CTCPResolverCall::PostponeNotify(NotifType theNotifType)
-
- {
- pendingNotify = theNotifType;
- Enqueue((QElemPtr) &qEntry, &((CTCPDriver::gTCPDriver)->asyncQueue));
- }
-
-
- /*______________________________________________________________________
- **
- ** PostponeStrToAddr (private static method)
- **
- ** Respond to notification that the StrToAddr call was completed.
- **
- ** hostInfoPtr (…): pointer to the DNR data structure (ignored)
- ** userDataPtr (char*): user data pointer (assumed to be CTCPResolver*)
- **
- */
-
- pascal void CTCPResolverCall::PostponeStrToAddr(struct hostInfo* hostInfoPtr, char* userDataPtr)
-
- {
- if (userDataPtr)
- ((CTCPResolverCall*) userDataPtr)->PostponeNotify(notifStrToAddr);
- }
-
-
- /*______________________________________________________________________
- **
- ** PostponeAddrToName (private static method)
- **
- ** Respond to notification that the AddrToName call was completed.
- **
- ** hostInfoPtr (…): pointer to the DNR data structure (ignored)
- ** userDataPtr (char*): user data pointer (assumed to be CTCPResolver*)
- **
- */
-
- pascal void CTCPResolverCall::PostponeAddrToName(struct hostInfo* hostInfoPtr, char* userDataPtr)
-
- {
- if (userDataPtr)
- ((CTCPResolverCall*) userDataPtr)->PostponeNotify(notifAddrToName);
- }
-
-
- /*______________________________________________________________________
- **
- ** PostponeHInfo (private static method)
- **
- ** Respond to notification that the HInfo call was completed.
- **
- ** hostInfoPtr (…): pointer to the DNR data structure (ignored)
- ** userDataPtr (char *): user data pointer (assumed to be CTCPResolver *)
- **
- */
-
- pascal void CTCPResolverCall::PostponeHInfo(struct returnRec* returnRecPtr, char* userDataPtr)
-
- {
- if (userDataPtr)
- ((CTCPResolverCall*) userDataPtr)->PostponeNotify(notifHInfo);
- }
-
-
- /*______________________________________________________________________
- **
- ** PostponeMXInfo (private static method)
- **
- ** Respond to notification that the MXInfo call was completed.
- **
- ** hostInfoPtr (…): pointer to the DNR data structure (ignored)
- ** userDataPtr (char*): user data pointer (assumed to be CTCPResolver*)
- **
- */
-
- pascal void CTCPResolverCall::PostponeMXInfo(struct returnRec* returnRecPtr, char* userDataPtr)
-
- {
- if (userDataPtr)
- ((CTCPResolverCall*) userDataPtr)->PostponeNotify(notifMXInfo);
- }
-